home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 1998 November / maximum-cd-1998-11.iso / Truespace 4 / Data / PROGRAM / Scripts / object.py < prev    next >
Encoding:
Python Source  |  1998-01-10  |  898 b   |  35 lines

  1. # MFC base classes.
  2. import sys
  3.  
  4. class Object:
  5.     def __init__(self, initObj = None):
  6.         self.__dict__['_obj_'] = initObj
  7. #        self._obj_ = initObj
  8.         if initObj: initObj.AttachObject(self)
  9.     def __del__(self):
  10.         self.close()
  11.     def __getattr__(self, attr):    # Make this object look like the underlying win32ui one.
  12.         try:    
  13.             # During cleanup __dict__ is not available, causing recursive death.
  14.             if attr != '__dict__':
  15.                 o = self.__dict__['_obj_']
  16.                 if o:
  17.                     return getattr(o, attr)
  18.         except KeyError:
  19.             pass
  20.         raise AttributeError, attr
  21.  
  22.     def OnAttachedObjectDeath(self):
  23. #        print "object", self.__class__.__name__, "dieing"
  24.         self._obj_ = None
  25.     def close(self):
  26.         if self.__dict__.has_key('_obj_'):
  27.             if self._obj_:
  28.                 self._obj_.AttachObject(None)
  29.                 self._obj_ = None
  30.  
  31. class CmdTarget(Object):
  32.     def __init__(self, initObj):
  33.         Object.__init__(self, initObj)
  34.  
  35.